class Event {
  constructor() {
    this.pool = {};
  }
  on(name, fn) {
    if (this.pool[name]) {
        this.pool[name].push(fn);
    } else {
        this.pool[name] = [fn];
    }
  }
  emit(name, arg) {
    const target = this.pool[name];
    if (target) {
      target.forEach((item) => item(arg));
    }
  }
  off(name, fn) {
    const target = this.pool[name];
    if (target) {
      const index = target.findIndex(fn);
      if (index > -1) {
        this.pool[name].splice(index, 1);
      }
    }
  }
  clear() {
    this.pool = {};
  }
  remove(name) {
    let target = this.pool[name];
    if (target) this.pool[name] = [];
  }
}
module.exports = new Event();
